package cuit.epoch.pymjl.distribuitedlock.factory;

import cuit.epoch.pymjl.distribuitedlock.lock.DistributedRedisLock;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.UUID;

/**
 * @author Pymjl
 * @version 1.0
 * @date 2022/10/18
 **/
@Component
public class DistributedLockClient {
    @Resource
    private StringRedisTemplate stringRedisTemplate;

    private String uuid;

    public DistributedLockClient() {
        this.uuid = UUID.randomUUID().toString();
    }

    public DistributedRedisLock getRedisLock(String lockName) {
        return new DistributedRedisLock(stringRedisTemplate, lockName, uuid);
    }
}
